package com.zr.domain.sp.controller.es;

import com.zr.domain.sp.tool.es.service.EsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class EsController {
    Logger logger = LoggerFactory.getLogger(EsController.class);

    @Autowired
    EsService esService;

    /*创建索引*/
    @RequestMapping("/createIndex")
    public String createIndex() {
        try {
            esService.createIndex();
            logger.info("success");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "ok";
    }


    /**
     * 判断索引存在
     */
    @RequestMapping("/existsIndex")
    public Boolean existsIndex() throws Exception {
        return esService.existsIndex();
    }

    /**
     * 删除索引
     */

    @RequestMapping("deleteIndex")
    public boolean deleteIndex() throws Exception {
        return esService.deleteIndex();
    }

    /**
     * 创建文档
     */
    @RequestMapping("createDoc")
    public String createDoc() throws Exception {
        return esService.createDoc();
    }

    /**
     * 判断文档是否存在
     */
    @RequestMapping("existsDoc")
    public boolean existsDoc() throws Exception {
        return esService.existsDoc();
    }

    /**
     获取文档
     */
    @RequestMapping("getDoc")
    public String getDoc() throws Exception {
        return esService.getDoc();
    }

    /**
     删除文档
     */
    @RequestMapping("deleteDoc")
    public String deleteDoc() throws Exception {
        return esService.deleteDoc();
    }
}
